{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import scipy.io as sio\n",
    "import h5py"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.把文件夹trainval里的文件名整理成训练集或者测试集的txt文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "\n",
    "path='/home/dl/DL_dataset/VOCdevkit/trainval'\n",
    "files=os.listdir(path)\n",
    "f=open(\"/home/dl/DL_dataset/VOCdevkit/train_aug.txt\",\"w\")\n",
    "#labels_path=os.path.join(path,'label2')\n",
    "#mat_file=sio(file_path)\n",
    "for afile in files:\n",
    "    file_path=os.path.join(path,afile)\n",
    "    if os.path.isfile(file_path):\n",
    "        if os.path.getsize(file_path)==0:\n",
    "            continue\n",
    "        print \"read it!\"\n",
    "        mat_idx=afile[:afile.find('.mat')]\n",
    "        f.write(\"/JPEGImages/\"+mat_idx+\".jpg \")\n",
    "        f.write(\"/PASCALContexts/\"+mat_idx+\".png\"+\"\\n\")\n",
    "        #dst_path=os.path.join(labels_path,mat_idx+'.png')\n",
    "        #label_img.save(dst_path)\n",
    "f.close()\n",
    "print \"finished!\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.将训练集或者测试集的txt文件处理成创建lmdb所需的单行文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/JPEGImages/2009_004368.jpg\n",
      "/JPEGImages/2010_002638.jpg\n",
      "/JPEGImages/2009_001542.jpg\n",
      "/JPEGImages/2009_002419.jpg\n",
      "/JPEGImages/2010_003534.jpg\n",
      "/JPEGImages/2008_002811.jpg\n",
      "/JPEGImages/2010_000495.jpg\n",
      "/JPEGImages/2010_002499.jpg\n",
      "/JPEGImages/2009_000453.jpg\n",
      "/JPEGImages/2008_007189.jpg\n",
      "/JPEGImages/2008_000233.jpg\n",
      "/JPEGImages/2010_005238.jpg\n",
      "/JPEGImages/2008_006462.jpg\n",
      "/JPEGImages/2010_004143.jpg\n",
      "/JPEGImages/2009_000136.jpg\n",
      "/JPEGImages/2009_003822.jpg\n",
      "/JPEGImages/2009_003666.jpg\n",
      "/JPEGImages/2010_002794.jpg\n",
      "/JPEGImages/2010_003931.jpg\n",
      "/JPEGImages/2009_002833.jpg\n",
      "/JPEGImages/2008_005433.jpg\n",
      "/JPEGImages/2010_004691.jpg\n",
      "/JPEGImages/2010_000647.jpg\n",
      "/JPEGImages/2010_002337.jpg\n",
      "/JPEGImages/2008_001523.jpg\n",
      "/JPEGImages/2010_001204.jpg\n",
      "/JPEGImages/2008_008095.jpg\n",
      "/JPEGImages/2010_001669.jpg\n",
      "/JPEGImages/2008_002873.jpg\n",
      "/JPEGImages/2008_002145.jpg\n",
      "/JPEGImages/2008_004457.jpg\n",
      "/JPEGImages/2008_003547.jpg\n",
      "/JPEGImages/2010_003092.jpg\n",
      "/JPEGImages/2008_007692.jpg\n",
      "/JPEGImages/2008_001741.jpg\n",
      "/JPEGImages/2008_004583.jpg\n",
      "/JPEGImages/2009_001783.jpg\n",
      "/JPEGImages/2009_003816.jpg\n",
      "/JPEGImages/2008_003624.jpg\n",
      "/JPEGImages/2010_002692.jpg\n",
      "/JPEGImages/2008_008666.jpg\n",
      "/JPEGImages/2009_000628.jpg\n",
      "/JPEGImages/2009_003950.jpg\n",
      "/JPEGImages/2008_006369.jpg\n",
      "/JPEGImages/2008_000174.jpg\n",
      "/JPEGImages/2010_002614.jpg\n",
      "/JPEGImages/2008_005245.jpg\n",
      "/JPEGImages/2008_007579.jpg\n",
      "/JPEGImages/2008_000908.jpg\n",
      "/JPEGImages/2010_005640.jpg\n",
      "/JPEGImages/2010_001710.jpg\n",
      "/JPEGImages/2008_000195.jpg\n",
      "/JPEGImages/2010_005805.jpg\n",
      "/JPEGImages/2009_005149.jpg\n",
      "/JPEGImages/2008_000806.jpg\n",
      "/JPEGImages/2010_004306.jpg\n",
      "/JPEGImages/2009_003753.jpg\n",
      "/JPEGImages/2008_000471.jpg\n",
      "/JPEGImages/2008_004621.jpg\n",
      "/JPEGImages/2009_003863.jpg\n",
      "/JPEGImages/2010_005152.jpg\n",
      "/JPEGImages/2008_004452.jpg\n",
      "/JPEGImages/2008_005874.jpg\n",
      "/JPEGImages/2009_004093.jpg\n",
      "/JPEGImages/2010_005543.jpg\n",
      "/JPEGImages/2010_004857.jpg\n",
      "/JPEGImages/2009_000377.jpg\n",
      "/JPEGImages/2010_004959.jpg\n",
      "/JPEGImages/2008_005101.jpg\n",
      "/JPEGImages/2009_004601.jpg\n",
      "/JPEGImages/2009_002960.jpg\n",
      "/JPEGImages/2010_001333.jpg\n",
      "/JPEGImages/2008_004754.jpg\n",
      "/JPEGImages/2009_004193.jpg\n",
      "/JPEGImages/2008_000700.jpg\n",
      "/JPEGImages/2009_001910.jpg\n",
      "/JPEGImages/2009_000931.jpg\n",
      "/JPEGImages/2008_008676.jpg\n",
      "/JPEGImages/2008_005065.jpg\n",
      "/JPEGImages/2008_008668.jpg\n",
      "/JPEGImages/2008_005764.jpg\n",
      "/JPEGImages/2009_005036.jpg\n",
      "/JPEGImages/2008_005574.jpg\n",
      "/JPEGImages/2009_003222.jpg\n",
      "/JPEGImages/2008_000711.jpg\n",
      "/JPEGImages/2010_003828.jpg\n",
      "/JPEGImages/2010_005386.jpg\n",
      "/JPEGImages/2010_001448.jpg\n",
      "/JPEGImages/2008_001395.jpg\n",
      "/JPEGImages/2009_004417.jpg\n",
      "/JPEGImages/2010_004105.jpg\n",
      "/JPEGImages/2008_004410.jpg\n",
      "/JPEGImages/2009_001980.jpg\n",
      "/JPEGImages/2009_001623.jpg\n",
      "/JPEGImages/2010_005432.jpg\n",
      "/JPEGImages/2009_005294.jpg\n",
      "/JPEGImages/2010_002333.jpg\n",
      "/JPEGImages/2009_003265.jpg\n",
      "/JPEGImages/2008_006793.jpg\n",
      "/JPEGImages/2009_003455.jpg\n",
      "/JPEGImages/2008_006746.jpg\n",
      "/JPEGImages/2008_006438.jpg\n",
      "/JPEGImages/2008_004138.jpg\n",
      "/JPEGImages/2008_001278.jpg\n",
      "/JPEGImages/2009_004016.jpg\n",
      "/JPEGImages/2010_003078.jpg\n",
      "/JPEGImages/2009_001740.jpg\n",
      "/JPEGImages/2009_004836.jpg\n",
      "/JPEGImages/2008_002590.jpg\n",
      "/JPEGImages/2009_000471.jpg\n",
      "/JPEGImages/2009_000562.jpg\n",
      "/JPEGImages/2008_002329.jpg\n",
      "/JPEGImages/2008_007635.jpg\n",
      "/JPEGImages/2008_001235.jpg\n",
      "/JPEGImages/2010_001893.jpg\n",
      "/JPEGImages/2008_000026.jpg\n",
      "/JPEGImages/2008_002804.jpg\n",
      "/JPEGImages/2008_007197.jpg\n",
      "/JPEGImages/2010_003800.jpg\n",
      "/JPEGImages/2010_005457.jpg\n",
      "/JPEGImages/2009_001268.jpg\n",
      "/JPEGImages/2010_004141.jpg\n",
      "/JPEGImages/2010_005332.jpg\n",
      "/JPEGImages/2009_000192.jpg\n",
      "/JPEGImages/2010_001399.jpg\n",
      "/JPEGImages/2010_003609.jpg\n",
      "/JPEGImages/2010_002526.jpg\n",
      "/JPEGImages/2010_000033.jpg\n",
      "/JPEGImages/2010_004656.jpg\n",
      "/JPEGImages/2008_002725.jpg\n",
      "/JPEGImages/2008_003814.jpg\n",
      "/JPEGImages/2008_005603.jpg\n",
      "/JPEGImages/2008_002985.jpg\n",
      "/JPEGImages/2008_005109.jpg\n",
      "/JPEGImages/2010_001253.jpg\n",
      "/JPEGImages/2009_001593.jpg\n",
      "/JPEGImages/2008_004006.jpg\n",
      "/JPEGImages/2008_001704.jpg\n",
      "/JPEGImages/2008_004243.jpg\n",
      "/JPEGImages/2008_006920.jpg\n",
      "/JPEGImages/2010_005346.jpg\n",
      "/JPEGImages/2009_005128.jpg\n",
      "/JPEGImages/2009_000216.jpg\n",
      "/JPEGImages/2008_007291.jpg\n",
      "/JPEGImages/2008_005699.jpg\n",
      "/JPEGImages/2010_000743.jpg\n",
      "/JPEGImages/2010_000139.jpg\n",
      "/JPEGImages/2008_008746.jpg\n",
      "/JPEGImages/2008_003041.jpg\n",
      "/JPEGImages/2010_003987.jpg\n",
      "/JPEGImages/2008_005679.jpg\n",
      "/JPEGImages/2009_000723.jpg\n",
      "/JPEGImages/2008_004427.jpg\n",
      "/JPEGImages/2010_001715.jpg\n",
      "/JPEGImages/2008_000373.jpg\n",
      "/JPEGImages/2009_002837.jpg\n",
      "/JPEGImages/2008_004110.jpg\n",
      "/JPEGImages/2010_005429.jpg\n",
      "/JPEGImages/2009_000759.jpg\n",
      "/JPEGImages/2009_002632.jpg\n",
      "/JPEGImages/2010_005676.jpg\n",
      "/JPEGImages/2008_005748.jpg\n",
      "/JPEGImages/2008_006631.jpg\n",
      "/JPEGImages/2010_004219.jpg\n",
      "/JPEGImages/2009_003537.jpg\n",
      "/JPEGImages/2010_005606.jpg\n",
      "/JPEGImages/2010_002392.jpg\n",
      "/JPEGImages/2008_003521.jpg\n",
      "/JPEGImages/2008_004071.jpg\n",
      "/JPEGImages/2008_004406.jpg\n",
      "/JPEGImages/2009_004202.jpg\n",
      "/JPEGImages/2009_001747.jpg\n",
      "/JPEGImages/2008_006708.jpg\n",
      "/JPEGImages/2008_008012.jpg\n",
      "/JPEGImages/2008_006064.jpg\n",
      "/JPEGImages/2008_004766.jpg\n",
      "/JPEGImages/2010_004558.jpg\n",
      "/JPEGImages/2010_002085.jpg\n",
      "/JPEGImages/2009_004556.jpg\n",
      "/JPEGImages/2009_000293.jpg\n",
      "/JPEGImages/2009_003071.jpg\n",
      "/JPEGImages/2009_004631.jpg\n",
      "/JPEGImages/2008_004258.jpg\n",
      "/JPEGImages/2008_008070.jpg\n",
      "/JPEGImages/2008_002467.jpg\n",
      "/JPEGImages/2009_000815.jpg\n",
      "/JPEGImages/2009_004148.jpg\n",
      "/JPEGImages/2010_004204.jpg\n",
      "/JPEGImages/2008_007286.jpg\n",
      "/JPEGImages/2009_002372.jpg\n",
      "/JPEGImages/2009_002192.jpg\n",
      "/JPEGImages/2010_001002.jpg\n",
      "/JPEGImages/2008_008080.jpg\n",
      "/JPEGImages/2010_002369.jpg\n",
      "/JPEGImages/2008_004416.jpg\n",
      "/JPEGImages/2009_004468.jpg\n",
      "/JPEGImages/2008_005361.jpg\n",
      "/JPEGImages/2008_006052.jpg\n",
      "/JPEGImages/2010_005071.jpg\n",
      "/JPEGImages/2008_002672.jpg\n",
      "/JPEGImages/2008_008393.jpg\n",
      "/JPEGImages/2008_004518.jpg\n",
      "/JPEGImages/2008_007739.jpg\n",
      "/JPEGImages/2009_003827.jpg\n",
      "/JPEGImages/2008_007640.jpg\n",
      "/JPEGImages/2008_002428.jpg\n",
      "/JPEGImages/2008_006912.jpg\n",
      "/JPEGImages/2008_004015.jpg\n",
      "/JPEGImages/2009_002242.jpg\n",
      "/JPEGImages/2010_004506.jpg\n",
      "/JPEGImages/2009_005025.jpg\n",
      "/JPEGImages/2009_000708.jpg\n",
      "/JPEGImages/2008_008021.jpg\n",
      "/JPEGImages/2009_002681.jpg\n",
      "/JPEGImages/2008_008423.jpg\n",
      "/JPEGImages/2010_002954.jpg\n",
      "/JPEGImages/2010_003197.jpg\n",
      "/JPEGImages/2008_002801.jpg\n",
      "/JPEGImages/2009_003199.jpg\n",
      "/JPEGImages/2008_006949.jpg\n",
      "/JPEGImages/2008_003323.jpg\n",
      "/JPEGImages/2010_005406.jpg\n",
      "/JPEGImages/2009_001884.jpg\n",
      "/JPEGImages/2010_000234.jpg\n",
      "/JPEGImages/2008_000981.jpg\n",
      "/JPEGImages/2008_004984.jpg\n",
      "/JPEGImages/2010_003547.jpg\n",
      "/JPEGImages/2008_003763.jpg\n",
      "/JPEGImages/2008_006424.jpg\n",
      "/JPEGImages/2008_005758.jpg\n",
      "/JPEGImages/2009_002629.jpg\n",
      "/JPEGImages/2008_001825.jpg\n",
      "/JPEGImages/2009_002648.jpg\n",
      "/JPEGImages/2010_001687.jpg\n",
      "/JPEGImages/2009_000419.jpg\n",
      "/JPEGImages/2010_003725.jpg\n",
      "/JPEGImages/2008_000251.jpg\n",
      "/JPEGImages/2010_005877.jpg\n",
      "/JPEGImages/2010_001808.jpg\n",
      "/JPEGImages/2008_006509.jpg\n",
      "/JPEGImages/2008_005257.jpg\n",
      "/JPEGImages/2009_003793.jpg\n",
      "/JPEGImages/2010_002113.jpg\n",
      "/JPEGImages/2008_000982.jpg\n",
      "/JPEGImages/2010_004179.jpg\n",
      "/JPEGImages/2008_006953.jpg\n",
      "/JPEGImages/2008_007864.jpg\n",
      "/JPEGImages/2008_002972.jpg\n",
      "/JPEGImages/2008_001160.jpg\n",
      "/JPEGImages/2009_001570.jpg\n",
      "/JPEGImages/2008_007610.jpg\n",
      "/JPEGImages/2008_001142.jpg\n",
      "/JPEGImages/2010_003854.jpg\n",
      "/JPEGImages/2008_006441.jpg\n",
      "/JPEGImages/2009_000171.jpg\n",
      "/JPEGImages/2008_004378.jpg\n",
      "/JPEGImages/2009_005152.jpg\n",
      "/JPEGImages/2010_002274.jpg\n",
      "/JPEGImages/2008_006700.jpg\n",
      "/JPEGImages/2010_002830.jpg\n",
      "/JPEGImages/2008_001666.jpg\n",
      "/JPEGImages/2008_005979.jpg\n",
      "/JPEGImages/2010_006023.jpg\n",
      "/JPEGImages/2008_003067.jpg\n",
      "/JPEGImages/2010_000590.jpg\n",
      "/JPEGImages/2009_000500.jpg\n",
      "/JPEGImages/2009_003961.jpg\n",
      "/JPEGImages/2010_000401.jpg\n",
      "/JPEGImages/2010_000711.jpg\n",
      "/JPEGImages/2008_002280.jpg\n",
      "/JPEGImages/2010_001868.jpg\n",
      "/JPEGImages/2008_005035.jpg\n",
      "/JPEGImages/2009_000742.jpg\n",
      "/JPEGImages/2008_005431.jpg\n",
      "/JPEGImages/2010_001732.jpg\n",
      "/JPEGImages/2009_002695.jpg\n",
      "/JPEGImages/2010_004878.jpg\n",
      "/JPEGImages/2009_002221.jpg\n",
      "/JPEGImages/2008_008382.jpg\n",
      "/JPEGImages/2008_006285.jpg\n",
      "/JPEGImages/2009_001133.jpg\n",
      "/JPEGImages/2010_005906.jpg\n",
      "/JPEGImages/2010_003252.jpg\n",
      "/JPEGImages/2010_002497.jpg\n",
      "/JPEGImages/2009_001509.jpg\n",
      "/JPEGImages/2008_003107.jpg\n",
      "/JPEGImages/2008_003753.jpg\n",
      "/JPEGImages/2008_003589.jpg\n",
      "/JPEGImages/2008_005566.jpg\n",
      "/JPEGImages/2008_005451.jpg\n",
      "/JPEGImages/2008_002852.jpg\n",
      "/JPEGImages/2009_001780.jpg\n",
      "/JPEGImages/2010_000578.jpg\n",
      "/JPEGImages/2008_008600.jpg\n",
      "/JPEGImages/2009_004133.jpg\n",
      "/JPEGImages/2008_004907.jpg\n",
      "/JPEGImages/2008_000910.jpg\n",
      "/JPEGImages/2008_007690.jpg\n",
      "/JPEGImages/2010_004149.jpg\n",
      "/JPEGImages/2008_000123.jpg\n",
      "/JPEGImages/2009_000385.jpg\n",
      "/JPEGImages/2010_004198.jpg\n",
      "/JPEGImages/2009_003259.jpg\n",
      "/JPEGImages/2008_003579.jpg\n",
      "/JPEGImages/2009_002348.jpg\n",
      "/JPEGImages/2008_007239.jpg\n",
      "/JPEGImages/2010_005026.jpg\n",
      "/JPEGImages/2010_006057.jpg\n",
      "/JPEGImages/2009_004440.jpg\n",
      "/JPEGImages/2010_001739.jpg\n",
      "/JPEGImages/2009_000145.jpg\n",
      "/JPEGImages/2008_007750.jpg\n",
      "/JPEGImages/2008_004665.jpg\n",
      "/JPEGImages/2009_003490.jpg\n",
      "/JPEGImages/2009_001369.jpg\n",
      "/JPEGImages/2010_001189.jpg\n",
      "/JPEGImages/2008_001781.jpg\n",
      "/JPEGImages/2008_007293.jpg\n",
      "/JPEGImages/2010_000498.jpg\n",
      "/JPEGImages/2010_003728.jpg\n",
      "/JPEGImages/2009_001758.jpg\n",
      "/JPEGImages/2009_004361.jpg\n",
      "/JPEGImages/2010_000110.jpg\n",
      "/JPEGImages/2009_001249.jpg\n",
      "/JPEGImages/2008_006968.jpg\n",
      "/JPEGImages/2010_002684.jpg\n",
      "/JPEGImages/2009_000629.jpg\n",
      "/JPEGImages/2008_005376.jpg\n",
      "/JPEGImages/2010_006062.jpg\n",
      "/JPEGImages/2008_007515.jpg\n",
      "/JPEGImages/2008_002856.jpg\n",
      "/JPEGImages/2009_003656.jpg\n",
      "/JPEGImages/2009_002445.jpg\n",
      "/JPEGImages/2008_001866.jpg\n",
      "/JPEGImages/2009_002749.jpg\n",
      "/JPEGImages/2008_008319.jpg\n",
      "/JPEGImages/2008_000187.jpg\n",
      "/JPEGImages/2009_002145.jpg\n",
      "/JPEGImages/2008_006797.jpg\n",
      "/JPEGImages/2008_002052.jpg\n",
      "/JPEGImages/2009_001810.jpg\n",
      "/JPEGImages/2010_005596.jpg\n",
      "/JPEGImages/2008_002495.jpg\n",
      "/JPEGImages/2008_000376.jpg\n",
      "/JPEGImages/2010_004451.jpg\n",
      "/JPEGImages/2009_001006.jpg\n",
      "/JPEGImages/2009_003271.jpg\n",
      "/JPEGImages/2008_008342.jpg\n",
      "/JPEGImages/2009_002570.jpg\n",
      "/JPEGImages/2009_003316.jpg\n",
      "/JPEGImages/2010_001850.jpg\n",
      "/JPEGImages/2009_002524.jpg\n",
      "/JPEGImages/2009_002097.jpg\n",
      "/JPEGImages/2008_008296.jpg\n",
      "/JPEGImages/2010_000133.jpg\n",
      "/JPEGImages/2008_008122.jpg\n",
      "/JPEGImages/2009_001374.jpg\n",
      "/JPEGImages/2008_003076.jpg\n",
      "/JPEGImages/2009_004784.jpg\n",
      "/JPEGImages/2008_007163.jpg\n",
      "/JPEGImages/2009_004518.jpg\n",
      "/JPEGImages/2008_001586.jpg\n",
      "/JPEGImages/2009_001937.jpg\n",
      "/JPEGImages/2009_003052.jpg\n",
      "/JPEGImages/2009_004031.jpg\n",
      "/JPEGImages/2009_002912.jpg\n",
      "/JPEGImages/2009_002558.jpg\n",
      "/JPEGImages/2008_006705.jpg\n",
      "/JPEGImages/2008_002954.jpg\n",
      "/JPEGImages/2009_005056.jpg\n",
      "/JPEGImages/2008_004462.jpg\n",
      "/JPEGImages/2008_000723.jpg\n",
      "/JPEGImages/2010_000524.jpg\n",
      "/JPEGImages/2008_005247.jpg\n",
      "/JPEGImages/2010_000942.jpg\n",
      "/JPEGImages/2009_002698.jpg\n",
      "/JPEGImages/2009_002299.jpg\n",
      "/JPEGImages/2009_003269.jpg\n",
      "/JPEGImages/2010_001425.jpg\n",
      "/JPEGImages/2008_001481.jpg\n",
      "/JPEGImages/2008_004656.jpg\n",
      "/JPEGImages/2010_002742.jpg\n",
      "/JPEGImages/2008_007788.jpg\n",
      "/JPEGImages/2008_001007.jpg\n",
      "/JPEGImages/2008_001205.jpg\n",
      "/JPEGImages/2008_001021.jpg\n",
      "/JPEGImages/2008_004422.jpg\n",
      "/JPEGImages/2010_001012.jpg\n",
      "/JPEGImages/2008_004768.jpg\n",
      "/JPEGImages/2009_003732.jpg\n",
      "/JPEGImages/2009_003181.jpg\n",
      "/JPEGImages/2010_002995.jpg\n",
      "/JPEGImages/2010_001310.jpg\n",
      "/JPEGImages/2009_001329.jpg\n",
      "/JPEGImages/2008_007998.jpg\n",
      "/JPEGImages/2008_007134.jpg\n",
      "/JPEGImages/2009_000793.jpg\n",
      "/JPEGImages/2009_004169.jpg\n",
      "/JPEGImages/2008_005283.jpg\n",
      "/JPEGImages/2009_003598.jpg\n",
      "/JPEGImages/2009_004942.jpg\n",
      "/JPEGImages/2008_007410.jpg\n",
      "/JPEGImages/2008_000021.jpg\n",
      "/JPEGImages/2010_005820.jpg\n",
      "/JPEGImages/2010_004415.jpg\n",
      "/JPEGImages/2008_001838.jpg\n",
      "/JPEGImages/2010_004951.jpg\n",
      "/JPEGImages/2009_003801.jpg\n",
      "/JPEGImages/2008_001551.jpg\n",
      "/JPEGImages/2008_007947.jpg\n",
      "/JPEGImages/2008_003676.jpg\n",
      "/JPEGImages/2010_004624.jpg\n",
      "/JPEGImages/2008_003776.jpg\n",
      "/JPEGImages/2008_001290.jpg\n",
      "/JPEGImages/2010_001292.jpg\n",
      "/JPEGImages/2009_004921.jpg\n",
      "/JPEGImages/2010_003520.jpg\n",
      "/JPEGImages/2008_004318.jpg\n",
      "/JPEGImages/2008_001661.jpg\n",
      "/JPEGImages/2009_001806.jpg\n",
      "/JPEGImages/2008_007435.jpg\n",
      "/JPEGImages/2008_001190.jpg\n",
      "/JPEGImages/2010_004466.jpg\n",
      "/JPEGImages/2010_000655.jpg\n",
      "/JPEGImages/2009_001990.jpg\n",
      "/JPEGImages/2008_006872.jpg\n",
      "/JPEGImages/2009_000641.jpg\n",
      "/JPEGImages/2010_003910.jpg\n",
      "/JPEGImages/2008_000828.jpg\n",
      "/JPEGImages/2008_007084.jpg\n",
      "/JPEGImages/2009_000928.jpg\n",
      "/JPEGImages/2009_000283.jpg\n",
      "/JPEGImages/2010_005974.jpg\n",
      "/JPEGImages/2009_003806.jpg\n",
      "/JPEGImages/2009_003350.jpg\n",
      "/JPEGImages/2009_003799.jpg\n",
      "/JPEGImages/2010_003539.jpg\n",
      "/JPEGImages/2009_001964.jpg\n",
      "/JPEGImages/2008_005072.jpg\n",
      "/JPEGImages/2008_000348.jpg\n",
      "/JPEGImages/2008_007476.jpg\n",
      "/JPEGImages/2008_003101.jpg\n",
      "/JPEGImages/2008_004513.jpg\n",
      "/JPEGImages/2009_003415.jpg\n",
      "/JPEGImages/2009_004934.jpg\n",
      "/JPEGImages/2008_006489.jpg\n",
      "/JPEGImages/2010_001550.jpg\n",
      "/JPEGImages/2008_007611.jpg\n",
      "/JPEGImages/2010_003762.jpg\n",
      "/JPEGImages/2008_004469.jpg\n",
      "/JPEGImages/2008_005641.jpg\n",
      "/JPEGImages/2009_000011.jpg\n",
      "/JPEGImages/2010_002979.jpg\n",
      "/JPEGImages/2008_006188.jpg\n",
      "/JPEGImages/2008_000837.jpg\n",
      "/JPEGImages/2009_002388.jpg\n",
      "/JPEGImages/2009_004857.jpg\n",
      "/JPEGImages/2010_005275.jpg\n",
      "/JPEGImages/2010_002537.jpg\n",
      "/JPEGImages/2010_003062.jpg\n",
      "/JPEGImages/2008_006207.jpg\n",
      "/JPEGImages/2009_003156.jpg\n",
      "/JPEGImages/2008_006067.jpg\n",
      "/JPEGImages/2009_003416.jpg\n",
      "/JPEGImages/2010_004104.jpg\n",
      "/JPEGImages/2009_005005.jpg\n",
      "/JPEGImages/2010_005957.jpg\n",
      "/JPEGImages/2010_000076.jpg\n",
      "/JPEGImages/2010_004523.jpg\n",
      "/JPEGImages/2009_002077.jpg\n",
      "/JPEGImages/2010_001364.jpg\n",
      "/JPEGImages/2009_003944.jpg\n",
      "/JPEGImages/2009_001074.jpg\n",
      "/JPEGImages/2008_008476.jpg\n",
      "/JPEGImages/2009_002216.jpg\n",
      "/JPEGImages/2010_003415.jpg\n",
      "/JPEGImages/2009_003142.jpg\n",
      "/JPEGImages/2009_002127.jpg\n",
      "/JPEGImages/2010_001572.jpg\n",
      "/JPEGImages/2010_001814.jpg\n",
      "/JPEGImages/2008_007514.jpg\n",
      "/JPEGImages/2009_001100.jpg\n",
      "/JPEGImages/2010_001569.jpg\n",
      "/JPEGImages/2010_002431.jpg\n",
      "/JPEGImages/2010_006015.jpg\n",
      "/JPEGImages/2010_000797.jpg\n",
      "/JPEGImages/2009_000820.jpg\n",
      "/JPEGImages/2008_005976.jpg\n",
      "/JPEGImages/2009_004174.jpg\n",
      "/JPEGImages/2010_000782.jpg\n",
      "/JPEGImages/2008_004232.jpg\n",
      "/JPEGImages/2008_007221.jpg\n",
      "/JPEGImages/2009_001308.jpg\n",
      "/JPEGImages/2009_001184.jpg\n",
      "/JPEGImages/2008_003288.jpg\n",
      "/JPEGImages/2010_004777.jpg\n",
      "/JPEGImages/2008_002558.jpg\n",
      "/JPEGImages/2010_003950.jpg\n",
      "/JPEGImages/2009_004052.jpg\n",
      "/JPEGImages/2008_007949.jpg\n"
     ]
    }
   ],
   "source": [
    "input_file='./pascal_context/list/test.txt'\n",
    "out_image_file='./pascal_context/list/test_images_lmdb.txt'\n",
    "out_label_file='./pascal_context/list/test_labels_lmdb.txt'\n",
    "def creat_lmdb_txt(input_file,out_image_file,out_label_file):\n",
    "    f = open(input_file,'r')   \n",
    "    t1=open(out_image_file,'w')\n",
    "    t2=open(out_label_file,'w')\n",
    "    lines = f.readlines()\n",
    "\n",
    "    for line in lines:\n",
    "        stopkey=line.split(' ',1)\n",
    "        t1.write('.'+stopkey[0]+'\\n')\n",
    "        t2.write('.'+stopkey[1])\n",
    "        print stopkey[0]\n",
    "        #print '['+stopkey[0]+']'\n",
    "creat_lmdb_txt(input_file,out_image_file,out_label_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/JPEGImages/2007_000033.jpg\n",
      "/JPEGImages/2007_000042.jpg\n",
      "/JPEGImages/2007_000061.jpg\n",
      "/JPEGImages/2007_000123.jpg\n",
      "/JPEGImages/2007_000129.jpg\n",
      "/JPEGImages/2007_000175.jpg\n",
      "/JPEGImages/2007_000187.jpg\n",
      "/JPEGImages/2007_000323.jpg\n",
      "/JPEGImages/2007_000332.jpg\n",
      "/JPEGImages/2007_000346.jpg\n",
      "/JPEGImages/2007_000452.jpg\n",
      "/JPEGImages/2007_000464.jpg\n",
      "/JPEGImages/2007_000491.jpg\n",
      "/JPEGImages/2007_000529.jpg\n",
      "/JPEGImages/2007_000559.jpg\n",
      "/JPEGImages/2007_000572.jpg\n",
      "/JPEGImages/2007_000629.jpg\n",
      "/JPEGImages/2007_000636.jpg\n",
      "/JPEGImages/2007_000661.jpg\n",
      "/JPEGImages/2007_000663.jpg\n",
      "/JPEGImages/2007_000676.jpg\n",
      "/JPEGImages/2007_000727.jpg\n",
      "/JPEGImages/2007_000762.jpg\n",
      "/JPEGImages/2007_000783.jpg\n",
      "/JPEGImages/2007_000799.jpg\n",
      "/JPEGImages/2007_000804.jpg\n",
      "/JPEGImages/2007_000830.jpg\n",
      "/JPEGImages/2007_000837.jpg\n",
      "/JPEGImages/2007_000847.jpg\n",
      "/JPEGImages/2007_000862.jpg\n",
      "/JPEGImages/2007_000925.jpg\n",
      "/JPEGImages/2007_000999.jpg\n",
      "/JPEGImages/2007_001154.jpg\n",
      "/JPEGImages/2007_001175.jpg\n",
      "/JPEGImages/2007_001239.jpg\n",
      "/JPEGImages/2007_001284.jpg\n",
      "/JPEGImages/2007_001288.jpg\n",
      "/JPEGImages/2007_001289.jpg\n",
      "/JPEGImages/2007_001299.jpg\n",
      "/JPEGImages/2007_001311.jpg\n",
      "/JPEGImages/2007_001321.jpg\n",
      "/JPEGImages/2007_001377.jpg\n",
      "/JPEGImages/2007_001408.jpg\n",
      "/JPEGImages/2007_001423.jpg\n",
      "/JPEGImages/2007_001430.jpg\n",
      "/JPEGImages/2007_001457.jpg\n",
      "/JPEGImages/2007_001458.jpg\n",
      "/JPEGImages/2007_001526.jpg\n",
      "/JPEGImages/2007_001568.jpg\n",
      "/JPEGImages/2007_001585.jpg\n",
      "/JPEGImages/2007_001586.jpg\n",
      "/JPEGImages/2007_001587.jpg\n",
      "/JPEGImages/2007_001594.jpg\n",
      "/JPEGImages/2007_001630.jpg\n",
      "/JPEGImages/2007_001677.jpg\n",
      "/JPEGImages/2007_001678.jpg\n",
      "/JPEGImages/2007_001717.jpg\n",
      "/JPEGImages/2007_001733.jpg\n",
      "/JPEGImages/2007_001761.jpg\n",
      "/JPEGImages/2007_001763.jpg\n",
      "/JPEGImages/2007_001774.jpg\n",
      "/JPEGImages/2007_001884.jpg\n",
      "/JPEGImages/2007_001955.jpg\n",
      "/JPEGImages/2007_002046.jpg\n",
      "/JPEGImages/2007_002094.jpg\n",
      "/JPEGImages/2007_002119.jpg\n",
      "/JPEGImages/2007_002132.jpg\n",
      "/JPEGImages/2007_002260.jpg\n",
      "/JPEGImages/2007_002266.jpg\n",
      "/JPEGImages/2007_002268.jpg\n",
      "/JPEGImages/2007_002284.jpg\n",
      "/JPEGImages/2007_002376.jpg\n",
      "/JPEGImages/2007_002378.jpg\n",
      "/JPEGImages/2007_002387.jpg\n",
      "/JPEGImages/2007_002400.jpg\n",
      "/JPEGImages/2007_002412.jpg\n",
      "/JPEGImages/2007_002426.jpg\n",
      "/JPEGImages/2007_002427.jpg\n",
      "/JPEGImages/2007_002445.jpg\n",
      "/JPEGImages/2007_002470.jpg\n",
      "/JPEGImages/2007_002539.jpg\n",
      "/JPEGImages/2007_002565.jpg\n",
      "/JPEGImages/2007_002597.jpg\n",
      "/JPEGImages/2007_002618.jpg\n",
      "/JPEGImages/2007_002619.jpg\n",
      "/JPEGImages/2007_002624.jpg\n",
      "/JPEGImages/2007_002643.jpg\n",
      "/JPEGImages/2007_002648.jpg\n",
      "/JPEGImages/2007_002719.jpg\n",
      "/JPEGImages/2007_002728.jpg\n",
      "/JPEGImages/2007_002823.jpg\n",
      "/JPEGImages/2007_002824.jpg\n",
      "/JPEGImages/2007_002852.jpg\n",
      "/JPEGImages/2007_002903.jpg\n",
      "/JPEGImages/2007_003011.jpg\n",
      "/JPEGImages/2007_003020.jpg\n",
      "/JPEGImages/2007_003022.jpg\n",
      "/JPEGImages/2007_003051.jpg\n",
      "/JPEGImages/2007_003088.jpg\n",
      "/JPEGImages/2007_003101.jpg\n"
     ]
    }
   ],
   "source": [
    "input_file='./voc2012/list/val.txt'\n",
    "out_image_file='./voc2012/list/test_images_1000_lmdb.txt'\n",
    "out_label_file='./voc2012/list/test_labels_1000_lmdb.txt'\n",
    "def creat_lmdb_txt(input_file,out_image_file,out_label_file):\n",
    "    f = open(input_file,'r')   \n",
    "    t1=open(out_image_file,'w')\n",
    "    t2=open(out_label_file,'w')\n",
    "    lines = f.readlines()\n",
    "    i=0\n",
    "    for line in lines:       \n",
    "        if i<100:\n",
    "            i=i+1\n",
    "            stopkey=line.split(' ',1)\n",
    "            t1.write('.'+stopkey[0]+'\\n')\n",
    "            t2.write('.'+stopkey[1])\n",
    "    print \"finish it!\"\n",
    "            #print '['+stopkey[0]+']'\n",
    "creat_lmdb_txt(input_file,out_image_file,out_label_file)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3.使用create_dataset_lmdb.py生成Semantic Segmentation的lmdb文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "python ../create_dataset_lmdb.py --W 500 --H 500 --output_path ./lmdb/test_labels_nyu_lmdb/ --input_images ./list/test_labels_lmdb.txt --nb_classes 459 --labels\n",
    "python ../create_dataset_lmdb.py --W 500 --H 500 --output_path ./lmdb/test_images_nyu_lmdb/ --input_images ./list/test_images_lmdb.txt --nb_classes 459\n",
    "python ../create_dataset_lmdb.py --W 500 --H 500 --output_path ./lmdb/train_labels_nyu_lmdb/ --input_images ./list/train_labels_lmdb.txt --nb_classes 459 --labels\n",
    "python ../create_dataset_lmdb.py --W 500 --H 500 --output_path ./lmdb/train_images_nyu_lmdb/ --input_images ./list/train_images_lmdb.txt --nb_classes 459\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
